package cn.com.nes.site.entity.em.crm.customer;

import cn.com.nes.common.exception.NoSuchEnumException;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * 客户级别 枚举
 *  值域对应 t_param 表 param_type=22
 *
 * @Author: ShenWei
 * @Date: 2024/05/08/14:07
 */
@Slf4j
public enum CustomerLevelEnum {

    // 客户级别
    _level_1("01","一级"),
    _level_2("02","二级"),
    _level_3("03","三级"),
    _level_4("04","四级"),
    _level_5("05","五级"),

    ;

    CustomerLevelEnum(String type, String title) {
        this.type = type;
        this.title = title;
    }

    private String type;

    private String title;

    public String getType() {
        return type;
    }

    public String getTitle() {
        return title;
    }

    public static CustomerLevelEnum getEnum(String key) {
        Map<String, CustomerLevelEnum> map = new HashMap<>();
        for (CustomerLevelEnum customerLevelEnum : values()) {
            map.put(customerLevelEnum.getType(), customerLevelEnum);
        }
        if (!map.containsKey(key)) {
            throw new NoSuchEnumException("未匹配的客户级别");
        }
        return map.get(String.valueOf(key));
    }

    public static String enumConvertKeyToValue(String key) {
        String val = "";
        try {
            val = getEnum(key).getTitle();
        } catch (NoSuchEnumException e) {
            log.warn("{}, convert key to value error, key:[{}], cause:[{}]", e.getStackTrace()[0].getFileName(), key, e.getMessage());
        }
        return val;
    }

}
